<!doctype html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,initial-scale=1.0,width=device-width"/>
    <meta name="format-detection" content="telephone=no,email=no,date=no,address=no">
    <title>大奔农庄</title>
    <link rel="stylesheet" type="text/css" href="../../css/aui.css"/>
    <link rel="stylesheet" type="text/css" href="../../css/style.css"/> 
    <link rel="stylesheet" type="text/css" href="../../css/aui-pull-refresh.css"/> 
</head>
<style type="text/css">
        .text-white {
            color: #ffffff !important;
        }
        .aui-grid [class*=aui-col-] {
            padding: 0.75rem 0;
        }
        .aui-list .aui-list-item:active {
     	background-color:#fff !important;
}
    </style>
<body>
<div class="cd_gr-center">
	<div class="user-div">
		<div class="user-tx" onclick="openShezhi();">
			  <img src="../../image/touxiang.jpg" class="aui-img-round" >
		</div>
		<h3 id="user_login" onclick="openLogin();">立即登录</h3>
		<h3 id="user_account" onclick="openShezhi();"></h3>
	</div>
	
	<section class="aui-content">
         <ul class="aui-list aui-list-in aui-margin-b-15">
         	<li class="aui-list-item db_user_aui-list-item" onclick="openYingyu()">
                <div class="aui-list-item-label-icon">
                    <img src="../../image/44.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">影娱</div>
                </div>
            </li>
            <li class="aui-list-item db_user_aui-list-item" onclick="openJinrong()">
                <div class="aui-list-item-label-icon" >
                    <img src="../../image/55.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">金融</div>
                </div>
            </li>
            <li class="aui-list-item db_user_aui-list-item" onclick="openXinxi()">
                <div class="aui-list-item-label-icon" >
                    <img src="../../image/66.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">信息</div>
                </div>
            </li>
            <li class="aui-list-item db_user_aui-list-item" onclick="openShenghuo()">
                <div class="aui-list-item-label-icon" >
                    <img src="../../image/77.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">生活</div>
                </div>
            </li>
         </ul>
         
          <ul class="aui-list aui-list-in aui-margin-b-15">
         	<li class="aui-list-item db_user_aui-list-item" onclick="openShoucang()">
                <div class="aui-list-item-label-icon">
                    <img src="../../image/11.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">我的收藏</div>
                </div>
            </li>
            <li class="aui-list-item db_user_aui-list-item" onclick="openAddress()">
                <div class="aui-list-item-label-icon" >
                    <img src="../../image/22.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">收货地址</div>
                </div>
            </li>
            <li class="aui-list-item db_user_aui-list-item" onclick="openMypingjia()">
                <div class="aui-list-item-label-icon" >
                    <img src="../../image/33.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">我的评价</div>
                </div>
            </li>
	        <li class="aui-list-item db_user_aui-list-item" onclick="openShezhi()">
                <div class="aui-list-item-label-icon">
                    <img src="../../image/1212.png" style="width:1.5rem">
                </div>
                <div class="aui-list-item-inner aui-list-item-arrow">
                    <div class="aui-list-item-title">设置</div>
                    <div class="aui-list-item-right"></div>
                </div>
	         </li>
	     </ul>
         
         <ul class="aui-list aui-list-in aui-margin-t-15 kefu_dianhua">
	            <a id="kefu_phone" class="aui-list-item db_user_aui-list-item aui-col-xs-6">
	                <div class="aui-list-item-label-icon">
	                    <img src="../../image/88.png" style="width:1.5rem">
	                </div>
	                <div class="aui-list-item-inner">
	                    <div class="aui-list-item-title">客服电话</div>
	                    <div class="aui-list-item-right"></div>
	                </div>
	            </a>
	            <li onclick="kefu();" id="kefu_qq" class="aui-list-item db_user_aui-list-item aui-col-xs-6">
	                <div class="aui-list-item-label-icon">
	                    <img src="../../image/99.png" style="width:1.5rem">
	                </div>
	                <div class="aui-list-item-inner">
	                    <div class="aui-list-item-title">QQ客服</div>
	                    <div class="aui-list-item-right"></div>
	                </div>
	            </li>
           </ul>
    </section>
    <div class="aui-content-padded" id='db_logout_button'>
		 <p><div class="aui-btn aui-btn-danger aui-btn-block" onclick="doLogout();">退出登录</div></p>
	</div>
</div>
</body>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/common.js"></script>
<script type="text/javascript" src="../../script/aui-pull-refresh.js"></script>
<script type="text/javascript" src="../../script/zepto.js"></script>
<script>
var db_key = 'user',db_user;
var my_info;
//页面初始化操作
apiready = function(){
    api.parseTapmode();
    getpeizhi();//获取平台配置信息
    getuser();//获取用户信息    
    //监听登录
    api.addEventListener({
        name: 'login_self'
    }, function(ret, err) {
        getuser();//获取用户信息
    });
    //监听退出登录
    api.addEventListener({
        name: 'mylogout'
    }, function(ret, err) {
        domreset();
    });
}
//下拉刷新，用户数据
var pullRefresh = new auiPullToRefresh({
    container: document.querySelector('.cd_gr-center'), //下拉容器
    triggerDistance: 100 //下拉高度
},function(ret){
    if(ret.status=="success"){
        setTimeout( function() {
        	getpeizhi();//获取平台配置信息
            getuser();//更新用户页面信息
            pullRefresh.cancelLoading(); //刷新成功后调用此方法隐藏
        },900)
    }
})
//获取用户储存在本地的数据方法
function getuser() {
    db_user = $api.getStorage(db_key);
    try {
        if (db_user.islogin && db_user.mytoken) {
            domfresh();
        }else {
            domreset();
        }
    }catch(e) {
        domreset();
    }
}
//更新用户数据方法
function domfresh() {
    var useData = {
        rtk : RSapi.myrtk,
        mytoken : db_user.mytoken,
    };
    
    api.ajax({
        url: RSapi.base+RSapi.Mdetail,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: useData },
    }, function(ret, err){
        if (err) {
            api.toast({msg:err.msg});
        }else {
            if (ret.status == 1) {
                my_info = ret.myinfo;
                $('#user_login').hide();
			    $('#user_account').show();
			    if(my_info.nickname){
					$('#user_account').html(my_info.nickname);			    
			    }else{
			    	$('#user_account').html(my_info.account);
			    }
			    $("#db_logout_button").show();
                $api.setStorage(db_key,db_user);
            }else {
                api.toast({msg:ret.info});
            }
        }
    });
    return false;
}
//获取平台配置信息
function getpeizhi() {
    var useData = {
        rtk : RSapi.myrtk,
    };
    api.ajax({
        url: RSapi.base+RSapi.PTdetail,
        method: 'post',
        cache: false,
        timeout: 30,
        dataType: 'json',
        data: { values: useData },
    }, function(ret, err){
        if (err) {
            api.toast({msg:err.msg});
        }else {
            if (ret.status == 1) {
            	//客服电话
                $api.attr($api.byId("kefu_phone"),'href','tel:'+ret.kefu_phone);  
                //客服qq
                $api.attr($api.byId("kefu_qq"),'data-qq',ret.kefu_qq);        
            }
        }
    });
    return false;
}
//退出登录或判断用户未登录时，界面显示数据重置
function domreset() {
    db_user = {islogin: false};
    $api.setStorage(db_key,db_user);
    $('#user_account').html('');
    $('#user_login').show();
    $('#user_account').hide();
    $("#db_logout_button").hide();
}
//退出登录
function doLogout() {
    if (db_user.islogin) {
        api.confirm({
            title: '退出登录',
            msg: '您确定退出登录吗？',
            buttons: ['确定', '取消']
        }, function(ret, err) {
            if (ret.buttonIndex == 1) {
                domreset();//重置页面数据
                var ajpush = api.require('ajpush');
                ajpush.bindAliasAndTags({alias:'unlogin'});
                api.toast({msg : '已经注销'});
                //发送注销事件
                api.sendEvent({
                    name: 'mylogout',
                    extra: {}
                });
            }
        });
    }else {
        api.toast({msg : '已经注销'});
    }
    return;
}
//登录
function openLogin(param) {
	api.openWin({
		name : "win_login",
		url : '../win/login_win.html',
		pageParam: {inself:true,param:param,winname:api.winName}
	});
}
//打开我的订单
function openOrder(){
	if (db_user.islogin) {
		api.openWin({
	        name: 'win_order',
	        url: '../win/order_win.html'
	    });
	}else {
        api.toast({ msg: '请先登录! ' });
        openLogin();
    }    
}
//打开我的收货地址
function openAddress(){
	if (db_user.islogin) {
		api.openWin({
	        name: 'win_address',
	        url: '../win/address_win.html'
	    });
	}else {
        api.toast({ msg: '请先登录! ' });
        openLogin();
    } 
}
//打开我的评价
function openMypingjia(){
	if (db_user.islogin) {
		api.openWin({
	        name: 'win_mypingjia',
	        url: '../win/mypingjia_win.html'
	    });
	}else {
        api.toast({ msg: '请先登录! ' });
        openLogin();
    } 
}
//打开设置
function openShezhi(){
	if (db_user.islogin) {
		api.openWin({
	        name: 'win_shezhi',
	        url: '../win/shezhi_win.html'
	    });
	}else {
        api.toast({ msg: '请先登录! ' });
        openLogin();
    }  
}
//打开我的收藏
function openShoucang(){
	if (db_user.islogin) {
		api.openWin({
	        name: 'win_shoucang',
	        url: '../win/shoucang_win.html'
	    });
	}else {
        api.toast({ msg: '请先登录! ' });
        openLogin();
    } 
}
//打开金融
function openJinrong(){
    api.openWin({
        name: 'win_Jinrong',
        url: '../win/jinrong_win.html'
    });
}
//打开影视娱乐
function openYingyu(){
    api.openWin({
        name: 'win_yingyu',
        url: '../win/yingyu_win.html'
    });
}
//打开生活导购
function openShenghuo(){
    api.openWin({
        name: 'win_shenghuo',
        url: '../win/shenghuo_win.html'
    });
}
//打开信息
function openXinxi(){
    api.openWin({
        name: 'win_Xinxi',
        url: '../win/xinxi_win.html'
    });
}
//打开qq
function kefu() {
	var number = $api.attr($api.byId('kefu_qq'), 'data-qq');
	api.openWin({
		name : 'win_webpage',
		url : 'webpage.html',
		pageParam : {
			title:'在线客服',
			url:'http://wpa.qq.com/msgrd?v=3&uin='+number+'&site=qq&menu=yes'
		}
	});
}
</script>
</html>